$(function(){
	//获取统计信息
	function requestData() {
		$.ajax({
       timeout:30000,
			url: window.Http + "/count/personal/wallet/table",
			type: 'GET',
			headers: {
				'Authorization': "Bearer " + sessionStorage.getItem('Token')
			},
			success: function (res) {
				if (res.code == 200) {
					$("#incomeNum").text(res.data.income||"0.00");
					$("#paymentNum").text(res.data.pay||"0.00");
					$("#rechargeNum").text(res.data.recharge||"0.00");
					$("#giveNum").text(res.data.send||"0.00");
					$("#statisticTime").text(res.data.lastCountTime);

				}

			}
		})
	}
	requestData();
	var totalListType = 1;//默认显示统计清单
	(function(){
		let parame = {
			productOwnerId:sessionStorage.getItem('UserId')
		};
		getTableRequest("/orderProduct/list",parame);
	}());

	$(".clickList").click(function(){
		let val = $(this).text();
		let parame = {};
		if(val.indexOf("收益") != -1){
			$("#listTitle").text("收益清单");
			totalListType = 1;
			parame.productOwnerId = sessionStorage.getItem('UserId');
			getTableRequest("/orderProduct/list",parame);
		}else if(val.indexOf("支付") != -1){
			$("#listTitle").text("支付清单");
			totalListType = 2;
			parame.userId = sessionStorage.getItem('UserId');
			getTableRequest("/orderProduct/list",parame);
		}else if(val.indexOf("充值") != -1){
			$("#listTitle").text("充值清单");
			totalListType = 3;
			parame.userId = sessionStorage.getItem('UserId');
			getTableRequest("/recharge/list",parame);
		}else if(val.indexOf("赠送") != -1){
			$("#listTitle").text("赠送清单");
			totalListType = 4;
			parame.userId = sessionStorage.getItem('UserId');
			getTableRequest("/joinActivity/list",parame);
		}
	})

	//获取清单内容数据
	function getTableRequest(url,parame){
		$.ajax({
       timeout:30000,
			url: window.Http + url,
			type: 'GET',
			headers: {
				'Authorization': "Bearer " + sessionStorage.getItem('Token')
			},
			data: {productOwnerId:sessionStorage.getItem('UserId')},
			success: function (res) {
				layer.closeAll('loading');
				if (res.code == 200) {
					renderTable(res.rows);
				}
			}
		})
	}
	//渲染表格
	function renderTable(data=[]){
		var tableHeader = [];
		switch (totalListType){
			case 2:
				tableHeader =[
							  {field:'id', width:80, title: 'ID'}
							  ,{field:'username', title: '名称'}
							  ,{field:'classify', title: '状态'}
							  ,{field:'sex', title: '金额'}
							  ,{field:'sign', title: '备注', maxWidth: 150}
							]
				break;
			case 3:
				tableHeader =[
							  {field:'id', width:80, title: 'ID'}
							  ,{field:'createTime', title: '充值日期', sort: true}
							  ,{field:'createBy', title: '用户名称'}
							  ,{field:'status', title: '状态'}
							  ,{field:'mode', title: '支付方式'}
							  ,{field:'amount', title: '金额', sort: true}
							  ,{field:'sign', title: '备注', maxWidth: 150}
							]
				break;
			case 4:
				tableHeader =[
							  {field:'id', width:80, title: 'ID'}
							  ,{field:'createBy', width:180, title: '用户名称'}
							  ,{field:'status',title: '状态'}
							  ,{field:'number', title: '赠送数量'}
							  ,{field:'joinTime', width:140, title: '开始日期', sort: true}
							  ,{field:'deadline', width:140, title: '截止日期', sort: true}
							  ,{field:'sign', title: '备注', maxWidth: 150}
							]
				break;
			default:
				tableHeader =[
							  {field:'id', width:80, title: 'ID'}
							  ,{field:'username', width:180, title: '产品名称'}
							  ,{field:'classify', width:80, title: '状态'}
							  ,{field:'sex', width:100, title: '卖出价格'}
							  ,{field:'city', width:100, title: '卖出数量'}
							  ,{field:'experience', width:140, title: '卖出日期', sort: true}
							  ,{field:'score', width:100, title: '金额', sort: true}
							  ,{field:'sign', title: '备注', maxWidth: 150}
							]
				break;
		}
		layui.use('table', function(){
		  var table = layui.table;
		  table.render({
		    elem: '#incomeAmountTable',
		    cols: [tableHeader],
			data:data,
		    page: true
		  });
		});
	}
})
